/*
    WiiCade Wii Remote API v2.0 
    Copyright (C) 2007 Jerason Banes

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    
    It is understood that no reaonable library system exists for Flash
    programs. To that end, this library is considered to be in library
    form when distributed as a source code package for linking to 
    Flash and Actionscript programs. Similarly, static linking of the
    library is understood to be the preferred form of distributing
    the library in binary form.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import com.wiicade.*;

class com.wiicade.Browser
{
    static private var buttonEnabled:Array;
    
    function Browser()
    {
        
    }
    
    static function init():Void
    {
        buttonEnabled = new Array();

        buttonEnabled[WiiRemote.BUTTON_LEFT] = false;
        buttonEnabled[WiiRemote.BUTTON_UP] = false;
        buttonEnabled[WiiRemote.BUTTON_RIGHT] = false;
        buttonEnabled[WiiRemote.BUTTON_DOWN] = false;

        buttonEnabled[WiiRemote.BUTTON_1] = false;
        buttonEnabled[WiiRemote.BUTTON_2] = false;
        buttonEnabled[WiiRemote.BUTTON_A] = false;
        buttonEnabled[WiiRemote.BUTTON_B] = false;

        buttonEnabled[WiiRemote.BUTTON_PLUS] = false;
        buttonEnabled[WiiRemote.BUTTON_MINUS] = false;
    }

    static public function isDefaultEnabled(buttonCode:Number):Boolean
    {
        if(!buttonEnabled) Wii.isWii();
        
        return buttonEnabled[buttonCode];
    }

    static public function setDefaultEnabled(buttonCode:Number, enabled:Boolean)
    {
        if(!buttonEnabled) Wii.isWii();
        
        buttonEnabled[buttonCode] = enabled;

        if(Wii.isWii()) getURL("javascript:enableWiiButton("+buttonCode+","+enabled+");");
    }

    static public function enableZooming():Void
    {
        setDefaultEnabled(WiiRemote.BUTTON_PLUS, true);
        setDefaultEnabled(WiiRemote.BUTTON_MINUS, true);
    }

    static public function disableZooming():Void
    {
        setDefaultEnabled(WiiRemote.BUTTON_PLUS, false);
        setDefaultEnabled(WiiRemote.BUTTON_MINUS, false);
    }

    static public function enableScrolling():Void
    {
        setDefaultEnabled(WiiRemote.BUTTON_LEFT, true);
        setDefaultEnabled(WiiRemote.BUTTON_RIGHT, true);
        setDefaultEnabled(WiiRemote.BUTTON_UP, true);
        setDefaultEnabled(WiiRemote.BUTTON_DOWN, true);
        setDefaultEnabled(WiiRemote.BUTTON_B, true);
    }

    static public function disableScrolling():Void
    {
        setDefaultEnabled(WiiRemote.BUTTON_LEFT, false);
        setDefaultEnabled(WiiRemote.BUTTON_RIGHT, false);
        setDefaultEnabled(WiiRemote.BUTTON_UP, false);
        setDefaultEnabled(WiiRemote.BUTTON_DOWN, false);
        setDefaultEnabled(WiiRemote.BUTTON_B, false);
    }
    
    static public function setBackgroundColor(color:Number):Void
    {
        if(Wii.isWii())
        {
            getURL("javascript:setBackgroundColor("+color+");");
        }
    }
}
